﻿#region 命名空间

using System;
using System.Web;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model;

#endregion

namespace WinnerCMS.WebUI.Templates.WinnerCMS6.Member
{
    public partial class Reg : WebFactory.ClientPublicPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request["Action"] == null)
                {
                    this.ZhuCe.Visible = true;
                    this.CG.Visible = false;
                }
                else
                {
                    this.ZhuCe.Visible = false;
                    this.CG.Visible = true;
                }

                var config = CMSConfig.Instance();
                if (config.Member.IsReg == false)
                {
                    MsgBox.Message("对不起。管理员已经关闭了会员注册！", "/", this);
                    this.btnReg.Enabled = false;
                }
            }
        }

        protected void btnReg_Click(object sender, EventArgs e)
        {
            if (PostData.PostFormRight() == false)
            {
                Response.Write("来源错误。");

                return;
            }
            var model = new User();
            model.Id = 0;
            model.UserName = this.txtName.Text.Trim();
            model.PassWord = this.txtPSW1.Text.Trim();
            model.PetName = this.txtPetName.Text.Trim();
            model.Question = this.txtQuestion.Text;
            model.Answer = this.txtAnswer.Text.Trim();
            model.EMail = this.txtemail.Text.Trim();
            model.Sex = byte.Parse(this.RBL_Sex.SelectedValue);
            model.HomePage = this.txtHomePage.Text.Trim();
            model.QQ = this.txtQQ.Text.Trim();
            model.Introduce = this.txtIntroduce.Text.Trim();

            model.Location = "";

            model.TrueName = this.txtTrueName.Text.Trim();
            model.Msn = this.txtMSN.Text.Trim();
            model.Birthday = this.txtBirthday.Text.Trim();
            model.Icq = this.txtICQ.Text.Trim();
            model.Yahoo = this.txtYahoo.Text.Trim();
            model.Skype = this.txtSkype.Text.Trim();
            model.IdCard = this.txtIdCard.Text.Trim();
            model.Mobile = this.txtMobile.Text.Trim();
            model.Phone = this.txtPhone.Text.Trim();
            model.Address = this.txtAddress.Text.Trim();


            string strErr = null;
            new Public_Member(false).RegMember(model, this.txtPassCode.Text, ref strErr);

            if (string.IsNullOrEmpty(strErr) == false)
            {
                MsgBox.Message(strErr, this);
            }
            else
            {
                HttpContext.Current.Response.Redirect("Reg.aspx?Action=Done");
            }
        }
    }
}